package com.ruoyi.system.media;


/**
 * 双片式OBU车辆信息文件(DF01/EF01)的编码信息
 * 79bytes
 *
 * @author wuxi_twz
 */
public class ObuEf01EdModel {
    public static final int MSG_LEN = 79;

    /**
     * 车牌号码(01-12,12,an)
     */
    public byte[] cCarPlat = new byte[12];

    /**
     * 车牌颜色(13-14,2,n)高字节： 00H	低字节：0x00 –蓝色； 0x01–黄色； 0x02 –黑色； 0x03 –白色； 0x04－渐变绿色； 0x05－黄绿双拼色； 0x06－蓝白渐变；0x07～ 0xFF 保留
     */
    public byte[] cPlatClr = new byte[2];

    /**
     * 车型(15-15,1,n)0~4:客1~客9；11~16：货1~货6；21~26：专1~专6
     */
    public byte[] nVchClss = new byte[1];

    /**
     * 用户类型(16-16,1,n)
     * 0-普通车； 6-公务车； 8-军警车； 10-紧急车； 12-免费；14-车队； 0～20 内其他：自定义；<br>
     * 21-绿通车； 22-联合收割机 ; 23-抢险救灾; 24－J1专用集装箱车；25-大件运输; 26－应急救援车；27－货车列车或半挂汽车列车;28-J2集装箱车
     */
    public byte[] nPayClss = new byte[1];

    /**
     * 车辆扩展信息(17-63,26,客货不同)
     */
    public byte[] vchExtend = new byte[63];

    /**
     * 信息编码
     *
     * @param dd
     * @return
     */
    public static ObuEf01EdModel encoded(ObuEf01Model dd) {
        ObuEf01EdModel ed = new ObuEf01EdModel();
        ed.cCarPlat = ZTools.str2bin(12, dd.cCarPlat);
        ed.cPlatClr = ZTools.int2bin(2, dd.cPlatClr);
        ed.nVchClss = ZTools.int2bin(1, dd.nVchClss);
        ed.nPayClss = ZTools.int2bin(1, dd.nPayClss);
        // 客车
        if (dd.nVchClss < 10) {
            ed.vchExtend = ZTools.sbMerger(ZTools.int2bin(2, dd.nVchSizeL / 100), ZTools.int2bin(1, dd.nVchSizeW / 100), ZTools.int2bin(1, dd.nVchSizeH / 100), ZTools.int2bin(1, dd.nVchWhel), ZTools.int2bin(1, dd.nVchAxis), ZTools.int2bin(2, dd.nVchAxLn / 100), ZTools.int2bin(3, dd.nVchSeat), ZTools.hex2bin(16, dd.specDesc), ZTools.hex2bin(16, dd.vehcleId), ZTools.hex2bin(20, dd.spare));
        } else {// 货车
            ed.vchExtend = ZTools.sbMerger(ZTools.int2bin(2, dd.nVchSizeL), ZTools.int2bin(2, dd.nVchSizeW), ZTools.int2bin(2, dd.nVchSizeH), ZTools.int2bin(3, dd.approvedLoad), ZTools.int2bin(3, dd.unladenMass), ZTools.int2bin(3, dd.grossMass), ZTools.int2bin(1, dd.nVchSeat), ZTools.hex2bin(17, dd.vehcleId), ZTools.hex2bin(16, dd.specDesc), ZTools.hex2bin(14, dd.spare));
        }

        return ed;
    }


//    public static ObuEf01EdModel sampleB() {// 客车
//        return ObuEf01EdModel.parse("C7E04148503838340000000000000100002D121004020018000005BCAAC0FBC5C64851363435334330330047424342303030333130370000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
//    }
//
//    public static ObuEf01EdModel sampleT() {// 货车
//        return ObuEf01EdModel.parse("C9C24545333131390000000000010E002ECC09F60F9600458800330E007918024C47415835443635344B3830313536340000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF");
//    }

    public byte[] toBytes() {
        byte[] ret = ZTools.sbMerger(cCarPlat, cPlatClr, nVchClss, nPayClss, vchExtend);
        return ret;
    }

    public String toHexStr() {
        return ZTools.bin2hex(toBytes());
    }

//    public void test1() {
//        ObuEf01EdModel ed1 = ObuEf01EdModel.sampleT();
//        String edHex = ed1.toHexStr();
//        ObuEf01EdModel ed2 = ObuEf01EdModel.parse(edHex);
//
//        ZTools.println(ed1.toHexStr());
//        ZTools.println(ed2.toHexStr());
//    }
//
//    public void test2() {
//        ObuEf01EdModel ed = ObuEf01EdModel.sampleT();
//        ObuEf01Model dd = ed.decoded();
//        ed = ObuEf01EdModel.encoded(dd);
//
//        ZTools.println(ed.toHexStr());
//        ZTools.println(JSON.toJSONString(dd));
//    }
//
//    public void test3() {
//        ObuEf01EdModel ed1 = ObuEf01EdModel.sampleT();
//        ObuEf01Model dd = ed1.decoded();
//        ObuEf01EdModel ed2 = ObuEf01EdModel.encoded(dd);
//        ZTools.println(ed1.toHexStr());
//        ZTools.println(ed2.toHexStr());
//    }

}
